import React,{useEffect,useState} from 'react'
// import axios from "axios"
// import "../../api/data";
import {ProductCard,Button,SubmitBar, Checkbox  } from 'react-vant';
import {useSelector,useDispatch} from "react-redux";
import {ALLTYPES,ADD,DEL} from "../../types/store.d"
function Shop() {
    const dispatch=useDispatch()
    interface DATATYPES{
        name?:string;
        id?:string;
        img?:string;
        num?:number;
        // list?:any;
    }
    // const [arr,setarr]=useState<Array<DATATYPES>>([])
    // useEffect(() => {
    //     axios.get("/api").then(res=>{
    //         // console.log(res);
    //         setarr(res.data.data)
    //     })
    // }, [])
    const arr=useSelector((state:ALLTYPES)=>{
        return state.list
    })
    console.log(arr);
    
    const add=(item:any)=>{
        dispatch({
            type:ADD,
            payload:item
        })
    }
    const del=(item:any)=>{
      dispatch({
        type:DEL,
        payload:item
      })
    }
    return (
        <div>
            {
                arr.map((item,index)=>{
                    return <ProductCard
                    key={index}
                    num={item.num}
                    price="120"
                    desc="描述信息"
                    title={item.name}
                    thumb={item.img}
                    footer={
                        <>
                          <Button onClick={()=>add(item)} size="mini" round plain style={{ marginRight: 2 }} >
                           加++
                          </Button>
                          <Button onClick={()=>del(item)}  size="mini" round plain style={{ marginRight: 2 }} >
                            减--
                          </Button>
                        </>
                      }
                  />
                })
            }
                <SubmitBar
      price="3050"
      buttonText="提交订单"
      tip={
        <>
          你的收货地址不支持同城送,
          <span style={{ color: '#1989fa' }}>修改地址</span>
        </>
      }
    >
      <Checkbox>全选</Checkbox>
    </SubmitBar>
        </div>
    )
}

export default Shop
